<?php

Raise::load('core.geometry.RaiseShape');
Raise::load('core.collection.RaiseTypedCollection');
Raise::load('core.geometry.RaisePoint');

/**
 * RaiseLine class
 * represents a line
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package phpraise.core.geometry
 * @since 1.2
 */
class RaiseLine extends RaiseShape {
    
    /**
     * The collection of points that this line will pass through
     * @var RaiseTypedCollection
     */
    private $points;

    /**
     * Create a new RaiseLine
     */
    public function __construct(){
        $this->points = new RaiseTypedCollection('RaisePoint');
    }

    /**
     * Return all the points of the line
     * @return RaiseTypedCollection
     */
    public function points(){
        return $this->points;
    }

    /**
     * Get the total distance of this line
     * @return integer|double
     */
    public function distance(){
        $t = null;
        $r = 0;
        foreach($this->points as $p){
            if($t != null){
                $r += $p->distance($t);
            }
            $t = $p;
        }
        return $r;
    }

}
